home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / gas / config / obj-ecoff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  9.1 KB  |  300 lines

  1. /* ECOFF object file format.
  2.    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.
  4.    This file was put together by Ian Lance Taylor <ian@cygnus.com>.
  5.  
  6.    This file is part of GAS.
  7.  
  8.    GAS is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    GAS is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with GAS; see the file COPYING.  If not, write to
  20.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  21.  
  22. #define OBJ_HEADER "obj-ecoff.h"
  23. #include "as.h"
  24. #include "coff/internal.h"
  25. #include "bfd/libcoff.h"
  26. #include "bfd/libecoff.h"
  27.  
  28. /* Almost all of the ECOFF support is actually in ecoff.c in the main
  29.    gas directory.  This file mostly just arranges to call that one at
  30.    the right times.  */
  31.  
  32. /* These are the pseudo-ops we support in this file.  Only those
  33.    relating to debugging information are supported here.
  34.  
  35.    The following pseudo-ops from the Kane and Heinrich MIPS book
  36.    should be defined here, but are currently unsupported: .aent,
  37.    .bgnb, .endb, .verstamp, .vreg.
  38.  
  39.    The following pseudo-ops from the Kane and Heinrich MIPS book are
  40.    MIPS CPU specific, and should be defined by tc-mips.c: .alias,
  41.    .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
  42.    .rdata, .sdata, .set.
  43.  
  44.    The following pseudo-ops from the Kane and Heinrich MIPS book are
  45.    not MIPS CPU specific, but are also not ECOFF specific.  I have
  46.    only listed the ones which are not already in read.c.  It's not
  47.    completely clear where these should be defined, but tc-mips.c is
  48.    probably the most reasonable place: .asciiz, .asm0, .endr, .err,
  49.    .half, .lab, .repeat, .struct, .weakext.  */
  50.  
  51. const pseudo_typeS obj_pseudo_table[] =
  52. {
  53.   /* COFF style debugging information. .ln is not used; .loc is used
  54.      instead.  */
  55.   { "def",    ecoff_directive_def,    0 },
  56.   { "dim",    ecoff_directive_dim,    0 },
  57.   { "endef",    ecoff_directive_endef,    0 },
  58.   { "file",    ecoff_directive_file,    0 },
  59.   { "scl",    ecoff_directive_scl,    0 },
  60.   { "size",    ecoff_directive_size,    0 },
  61.   { "esize",    ecoff_directive_size,    0 },
  62.   { "tag",    ecoff_directive_tag,    0 },
  63.   { "type",    ecoff_directive_type,    0 },
  64.   { "etype",    ecoff_directive_type,    0 },
  65.   { "val",    ecoff_directive_val,    0 },
  66.  
  67.   /* ECOFF specific debugging information.  */
  68.   { "begin",    ecoff_directive_begin,    0 },
  69.   { "bend",    ecoff_directive_bend,    0 },
  70.   { "end",    ecoff_directive_end,    0 },
  71.   { "ent",    ecoff_directive_ent,    0 },
  72.   { "fmask",    ecoff_directive_fmask,    0 },
  73.   { "frame",    ecoff_directive_frame,    0 },
  74.   { "loc",    ecoff_directive_loc,    0 },
  75.   { "mask",    ecoff_directive_mask,    0 },
  76.  
  77.   /* Other ECOFF directives.  */
  78.   { "extern",    ecoff_directive_extern,    0 },
  79.   { "weakext",    ecoff_directive_weakext, 0 },
  80.  
  81.   /* These are used on Irix.  I don't know how to implement them.  */
  82.   { "bgnb",    s_ignore,        0 },
  83.   { "endb",    s_ignore,        0 },
  84.   { "verstamp",    s_ignore,        0 },
  85.  
  86.   /* Sentinel.  */
  87.   { NULL }
  88. };
  89.  
  90. /* Swap out the symbols and debugging information for BFD.  */
  91.  
  92. void
  93. ecoff_frob_file ()
  94. {
  95.   const struct ecoff_debug_swap * const debug_swap
  96.     = &ecoff_backend (stdoutput)->debug_swap;
  97.   bfd_vma addr;
  98.   asection *sec;
  99.   HDRR *hdr;
  100.   char *buf;
  101.   char *set;
  102.  
  103.   /* Set the section VMA values.  We force the .sdata and .sbss
  104.      sections to the end to ensure that their VMA addresses are close
  105.      together so that the GP register can address both of them.  We
  106.      put the .bss section after the .sbss section.
  107.  
  108.      Also, for the Alpha, we must sort the sections, to make sure they
  109.      appear in the output file in the correct order.  (Actually, maybe
  110.      this is a job for BFD.  But the VMAs computed would be out of
  111.      whack if we computed them given our initial, random ordering.
  112.      It's possible that that wouldn't break things; I could do some
  113.      experimenting sometime and find out.
  114.  
  115.      This output ordering of sections is magic, on the Alpha, at
  116.      least.  The .lita section must come before .lit8 and .lit4,
  117.      otherwise the OSF/1 linker may silently trash the .lit{4,8}
  118.      section contents.  Also, .text must preceed .rdata.  These differ
  119.      from the order described in some parts of the DEC OSF/1 Assembly
  120.      Language Programmer's Guide, but that order doesn't seem to work
  121.      with their linker.
  122.  
  123.      I don't know if section ordering on the MIPS is important.  */
  124.  
  125.   static const char *const names[] = {
  126.     /* text segment */
  127.     ".text", ".rdata", ".init", ".fini",
  128.     /* data segment */
  129.     ".data", ".lita", ".lit8", ".lit4", ".sdata", ".got",
  130.     /* bss segment */
  131.     ".sbss", ".bss",
  132.   };
  133. #define n_names (sizeof (names) / sizeof (names[0]))
  134.  
  135.   addr = 0;
  136.   {
  137.     /* Sections that match names, order to be straightened out later.  */
  138.     asection *secs[n_names];
  139.     /* Linked list of sections with non-matching names.  Random ordering.  */
  140.     asection *other_sections = 0;
  141.     /* Pointer to next section, since we're destroying the original
  142.        ordering.  */
  143.     asection *next;
  144.  
  145.     int i;
  146.  
  147.     for (i = 0; i < n_names; i++)
  148.       secs[i] = 0;
  149.     for (sec = stdoutput->sections; sec != (asection *) NULL; sec = next)
  150.       {
  151.     next = sec->next;
  152.     for (i = 0; i < n_names; i++)
  153.       if (!strcmp (sec->name, names[i]))
  154.         {
  155.           secs[i] = sec;
  156.           break;
  157.         }
  158.     if (i == n_names)
  159.       {
  160.         bfd_set_section_vma (stdoutput, sec, addr);
  161.         addr += bfd_section_size (stdoutput, sec);
  162.         sec->next = other_sections;
  163.         other_sections = sec;
  164.       }
  165.       }
  166.     for (i = 0; i < n_names; i++)
  167.       if (secs[i])
  168.     {
  169.       sec = secs[i];
  170.       bfd_set_section_vma (stdoutput, sec, addr);
  171.       addr += bfd_section_size (stdoutput, sec);
  172.     }
  173.     for (i = n_names - 1; i >= 0; i--)
  174.       if (secs[i])
  175.     {
  176.       sec = secs[i];
  177.       sec->next = other_sections;
  178.       other_sections = sec;
  179.     }
  180.     stdoutput->sections = other_sections;
  181.   }
  182.  
  183.   /* Build the ECOFF debugging information.  */
  184.   assert (ecoff_data (stdoutput) != 0);
  185.   hdr = &ecoff_data (stdoutput)->debug_info.symbolic_header;
  186.   ecoff_build_debug (hdr, &buf, debug_swap);
  187.  
  188.   /* Finish up the ecoff_tdata structure.  */
  189.   set = buf;
  190. #define SET(ptr, count, type, size) \
  191.   if (hdr->count == 0) \
  192.     ecoff_data (stdoutput)->debug_info.ptr = (type) NULL; \
  193.   else \
  194.     { \
  195.       ecoff_data (stdoutput)->debug_info.ptr = (type) set; \
  196.       set += hdr->count * size; \
  197.     }
  198.  
  199.   SET (line, cbLine, unsigned char *, sizeof (unsigned char));
  200.   SET (external_dnr, idnMax, PTR, debug_swap->external_dnr_size);
  201.   SET (external_pdr, ipdMax, PTR, debug_swap->external_pdr_size);
  202.   SET (external_sym, isymMax, PTR, debug_swap->external_sym_size);
  203.   SET (external_opt, ioptMax, PTR, debug_swap->external_opt_size);
  204.   SET (external_aux, iauxMax, union aux_ext *, sizeof (union aux_ext));
  205.   SET (ss, issMax, char *, sizeof (char));
  206.   SET (ssext, issExtMax, char *, sizeof (char));
  207.   SET (external_rfd, crfd, PTR, debug_swap->external_rfd_size);
  208.   SET (external_fdr, ifdMax, PTR, debug_swap->external_fdr_size);
  209.   SET (external_ext, iextMax, PTR, debug_swap->external_ext_size);
  210.  
  211. #undef SET
  212.  
  213.   /* Fill in the register masks.  */
  214.   {
  215.     unsigned long gprmask = 0;
  216.     unsigned long fprmask = 0;
  217.     unsigned long *cprmask = NULL;
  218.  
  219. #ifdef TC_MIPS
  220.     /* Fill in the MIPS register masks.  It's probably not worth
  221.        setting up a generic interface for this.  */
  222.     gprmask = mips_gprmask;
  223.     cprmask = mips_cprmask;
  224. #endif
  225.  
  226. #ifdef TC_ALPHA
  227.     alpha_frob_ecoff_data ();
  228.  
  229.     if (! bfd_ecoff_set_gp_value (stdoutput, alpha_gp_value))
  230.       as_fatal ("Can't set GP value");
  231.  
  232.     gprmask = alpha_gprmask;
  233.     fprmask = alpha_fprmask;
  234. #endif
  235.  
  236.     if (! bfd_ecoff_set_regmasks (stdoutput, gprmask, fprmask, cprmask))
  237.       as_fatal ("Can't set register masks");
  238.   }
  239. }
  240.  
  241. /* This is called by the ECOFF code to set the external information
  242.    for a symbol.  We just pass it on to BFD, which expects the swapped
  243.    information to be stored in the native field of the symbol.  */
  244.  
  245. void
  246. obj_ecoff_set_ext (sym, ext)
  247.      symbolS *sym;
  248.      EXTR *ext;
  249. {
  250.   const struct ecoff_debug_swap * const debug_swap
  251.     = &ecoff_backend (stdoutput)->debug_swap;
  252.   ecoff_symbol_type *esym;
  253.  
  254.   know (bfd_asymbol_flavour (sym->bsym) == bfd_target_ecoff_flavour);
  255.   esym = ecoffsymbol (sym->bsym);
  256.   esym->local = false;
  257.   esym->native = xmalloc (debug_swap->external_ext_size);
  258.   (*debug_swap->swap_ext_out) (stdoutput, ext, esym->native);
  259. }
  260.  
  261. static int
  262. ecoff_sec_sym_ok_for_reloc (sec)
  263.      asection *sec;
  264. {
  265.   return 1;
  266. }
  267.  
  268. static void
  269. obj_ecoff_frob_symbol (sym, puntp)
  270.      symbolS *sym;
  271.      int *puntp;
  272. {
  273.   ecoff_frob_symbol (sym);
  274. }
  275.  
  276. static void
  277. ecoff_pop_insert ()
  278. {
  279.   pop_insert (obj_pseudo_table);
  280. }
  281.  
  282. const struct format_ops ecoff_format_ops =
  283. {
  284.   bfd_target_ecoff_flavour,
  285.   0,
  286.   1,
  287.   obj_ecoff_frob_symbol,
  288.   ecoff_frob_file,
  289.   0, 0,
  290.   0, 0,
  291.   0,
  292.   ecoff_generate_asm_lineno,
  293.   ecoff_stab,
  294.   ecoff_sec_sym_ok_for_reloc,
  295.   ecoff_pop_insert,
  296.   ecoff_set_ext,
  297.   ecoff_read_begin_hook,
  298.   ecoff_symbol_new_hook,
  299. };
  300.